﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.general.system.mobile_sms
{
    public partial class out_priv : ModulePage
    {
        private string GetDeptName(SqlConnection conn, int parentDept, string deptName)
        {
            if (parentDept != 0)
            {
                this.GetDept(conn, parentDept, ref deptName);
            }
            return deptName;
        }
        private void GetDept(SqlConnection conn, int deptId, ref string deptName)
        {
            string commandText = "SELECT [ParentDept],[DeptName] FROM [dbo].[Department] WHERE [DeptId] = " + deptId.ToString();
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText).Tables[0];
            if (table.Rows.Count > 0)
            {
                deptName = table.Rows[0]["DeptName"].ToString() + "/" + deptName;
                if (Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()) != 0)
                {
                    this.GetDept(conn, Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()), ref deptName);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string commandText = "";
            string str2 = "";
            if (!this.Page.IsPostBack)
            {
                commandText = "SELECT ISNULL(OutPriv,'') FROM Mobile_Priv";
                str2 = ",";
                str2 = str2 + ((string)SqlHelper.ExecuteScalar(base.Conn, CommandType.Text, commandText)) + ",";
                DataTable table = new UsersDao().SelectBaseAll(base.Conn);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        ListItem item = new ListItem("[" + this.GetDeptName(base.Conn, Convert.ToInt32(table.Rows[i]["ParentDept"].ToString()), table.Rows[i]["DeptName"].ToString()) + "] " + table.Rows[i]["UserName"].ToString(), table.Rows[i]["UserId"].ToString());
                        if (str2.IndexOf("," + table.Rows[i]["UserId"].ToString() + ",") >= 0)
                        {
                            this.pklOutPriv.ItemsLeft.Add(item);
                        }
                        else
                        {
                            this.pklOutPriv.ItemsRight.Add(item);
                        }
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                foreach (ListItem item2 in this.pklOutPriv.ItemsLeft)
                {
                    str2 = str2 + item2.Value + ",";
                }
                commandText = "UPDATE Mobile_Priv SET OutPriv = '" + str2 + "'";
                SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText);
                ConfigManager.Update();
                this.litMessage.Text = base.ShowPrompt("设置已保存", "out_priv.aspx");
            }
        }

 

 

    }
}
